package com.lazy.service.impl;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.lazy.common.dao.impl.BaseDaoImpl;
import com.lazy.common.exception.crmLazyException;
import com.lazy.common.utils.ModelUtil;
import com.lazy.common.utils.entity.Page;
import com.lazy.dao.UserMapper;
import com.lazy.domain.dto.UserDTO;
import com.lazy.domain.entity.UserDO;
import com.lazy.domain.vo.UserVO;
import com.lazy.service.UserService;

/**
 * @Auther: lujia
 * @Title: UserServiceImpl.java
 * @Description: (请用一句话来描述)
 * @Date:2019年12月11日 15:54:06
 * @Version: 1.0
 */
@Service
public class UserServiceImpl  extends BaseDaoImpl  implements UserService{
	@Autowired
	private UserMapper dao;
	@Override
	public UserVO saveUser(UserDTO user) throws crmLazyException {
		UserDO  userDo=ModelUtil.copyModel(user, UserDO.class);
		int flag=dao.insertUser(userDo);
		if(flag==0)
			throw new crmLazyException("插入用户失败");
		return ModelUtil.copyModel(userDo, UserVO.class);
	}

	@Override
	public UserVO updateUser(UserDTO user) throws crmLazyException {
		UserDO  userDo=ModelUtil.copyModel(user, UserDO.class);
		int flag=dao.insertUser(userDo);
		if(flag==0)
			throw new crmLazyException("插入用户失败");
		return ModelUtil.copyModel(userDo, UserVO.class);
	}

	@Override
	public UserVO getUser(Long id) {
		UserDO  userDo=dao.selectByPrimaryKey(id);
		return ModelUtil.copyModel(userDo, UserVO.class);
	}

	@Override
	public boolean deleteUser(Long id) throws crmLazyException {
		int flag=dao.deleteUser(id);
		if(flag==0)
			throw new crmLazyException("删除用户失败");
		return false;
	}

}
